package l.l.w.CodingInterviews;

/**
 * Created by llw on 2018/3/31/0031.
 */
public class 第一个只出现一次的字符 {
    public int FirstNotRepeatingChar(String str) {
        int[] array = new int[256];
        for(int i = 0; i < str.length();++i){
            char c = str.charAt(i);
            if(array[c] > 0) array[c] = -1;
            if(array[c] == 0) array[c] = i+1;
        }
        int index = 10002;
        for(int i = 0; i <256; ++i){
            if(array[i] > 0)
                if(index > array[i]) index = array[i];
        }
        if(index > 10002) return -1;
        else return index-1;
    }

    public static void main(String[] args) {
        int result = new 第一个只出现一次的字符().FirstNotRepeatingChar("google");
        System.out.println(result);
    }
}
